# -*-coding:utf-8 -*-
"""
@project: gnss
@authoe:  cjw
@time:    2019-07-31 15-23-52
@email:   https://gitee.com/cjwgitee
"""
from datetime import datetime
from company.models import VehicleCompanyTerminal
from media.models import VideoStream
from third_api.jpush_client import JPushClient
from third_api.ky import KYApi


class Player:
    '''播放器
    '''

    def __init__(self, *args, **kwargs):
        self.ky_api = KYApi()
        self.jpush_client = JPushClient()
        self.command_map = {
            1: {
                "_1": "1001",
                "_2": "1002"
            },
            0: {
                "_1": "1005",
                "_2": "1005"
            }
        }

    def start(self, vehicle_id, channel_id, device_type, terminal, vct):
        '''播放
        '''
        action = 1

        if device_type == 'KY':
            return self.ky_api.live(vehicle_id, terminal.imei, channel_id, action)
        else:
            if channel_id == 0:
                return self.jpush_client.push(vct.vehicle.vin, self.command_map[action]["_1"], '_1')
            else:
                return self.jpush_client.push(vct.vehicle.vin, self.command_map[action]["_2"], '_2')

    def stop(self, vehicle_id, channel_id, device_type, terminal, vct):
        '''停止播放
        '''
        action = 0
        if device_type == 'KY':
            return self.ky_api.live(vehicle_id, terminal.imei, channel_id, action)
        else:
            if channel_id == 0:
                return self.jpush_client.push(vct.vehicle.vin, self.command_map[action]["_1"], '_1')
            else:
                return self.jpush_client.push(vct.vehicle.vin, self.command_map[action]["_2"], '_2')
